﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _2.StudentsRecords
{
    class Program
    {
        static void Main(string[] args)
        {
            SerializeDeserializeTest();
            DeleteTest();
        }
        
        static void ShiftBytesTest()
        {
            string fileName = "shift.txt";
            SerializerHelper.ShiftBytesToLeft(fileName, 5, 10);
        }

        static void SerializeDeserializeTest()
        {
            Console.WriteLine("Serialization/Deserialization Test:");

            string fileName = "records.txt";
            File.Delete(fileName);

            Student s1 = new Student("1gesh", "kirov", 2);
            Student s2 = new Student("2slav", "ala bala", 22);
            Student s3 = new Student("3pesh", "bebe", 22);
            Student s4 = new Student("4kire", "mandja", 3);
            Student s5 = new Student("5gesh", "kirov", 2);
            Student s6 = new Student("6slav", "ala bala", 22);
            Student s7 = new Student("7pesh", "bebe", 22);
            Student s8 = new Student("8kire", "mandja", 3);

            SerializerHelper.AppendStudentToFile(fileName, s1);
            SerializerHelper.AppendStudentToFile(fileName, s2);
            SerializerHelper.AppendStudentToFile(fileName, s3);
            SerializerHelper.AppendStudentToFile(fileName, s4);
            SerializerHelper.AppendStudentToFile(fileName, s5);
            SerializerHelper.AppendStudentToFile(fileName, s6);
            SerializerHelper.AppendStudentToFile(fileName, s7);
            SerializerHelper.AppendStudentToFile(fileName, s8);

            var students = SerializerHelper.GetStudentsFromFile(fileName);

            foreach (Student s in students)
            {
                Console.WriteLine(s.FirstName);
            }
        }

        private static void DeleteTest()
        {
            Console.WriteLine("Deletion Test:");

            string fileName = "records.txt";
            SerializerHelper.DeleteAllStudentsWithFN(fileName, 22);

            var students = SerializerHelper.GetStudentsFromFile(fileName);

            foreach (Student s in students)
            {
                Console.WriteLine(s.FirstName);
            }
        }

    }
}
